package com.penghaisoft.microwms.product.service.impl;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.service.BaseService;
import com.penghaisoft.microwms.common.wms.model.ProCountingTask;
import com.penghaisoft.microwms.product.dao.ProCountingTaskMapper;
import com.penghaisoft.microwms.product.service.IProCountingTaskService;

/**
 * <p>
 * 业务逻辑实现类
 * </p>
 * 
 * @author
 * @createDate
 **/
@Service("proCountingTaskService")
public class ProCountingTaskServiceImpl extends BaseService implements IProCountingTaskService {
	@Resource
	private ProCountingTaskMapper proCountingTaskMapper;

	/**
	 * 新增记录
	 * 
	 * @param baseResource
	 * @return
	 */
	@Override
	public Resp create(ProCountingTask proCountingTask) {
		proCountingTaskMapper.create(proCountingTask);
		return success();
	}

	/**
	 * 删除记录（逻辑删除）
	 * 
	 * @param baseResource
	 * @return
	 */
	@Override
	public Resp delete(ProCountingTask proCountingTask) {
		proCountingTaskMapper.delete(proCountingTask);
		return success();
	}

	/**
	 * 查询列表
	 * 
	 * @param pager
	 * @param baseResource
	 * @return
	 */
	@Override
	public Pager<ProCountingTask> findListByCondition(int page, int rows, ProCountingTask condition) {
		Pager<ProCountingTask> pager = new Pager<>();
		pager.setPage(page);
		pager.setRows(rows);
		condition.preQuery();
		List<ProCountingTask> records = proCountingTaskMapper.queryList(pager, condition);
		long size = proCountingTaskMapper.queryCount(condition);
		pager.setRecords(records);
		pager.setTotalCount(size);
		return pager;
	}

	/**
	 * 查询单条
	 * 
	 * @param id
	 * @return
	 */
	@Override
	public ProCountingTask findById(String id) {
		return proCountingTaskMapper.queryById(id);
	}

	/**
	 * 修改记录
	 * 
	 * @param baseResource
	 * @return
	 */
	@Override
	public Resp update(ProCountingTask proCountingTask) {
		Integer updateCnt = proCountingTaskMapper.updateBySelect(proCountingTask);
		if (updateCnt.intValue() == 1) {
			return success();
		} else {
			return fail("更改状态失败");
		}
	}

	@Override
	public List<ProCountingTask> queryByAny(ProCountingTask proCountingTask) {

		return proCountingTaskMapper.queryByAny(proCountingTask);
	}

	/*
	 * @Title: updateProCountingTask
	 * @Description: 将盘点任务状态置为盘点中
	 * @author jzh
	 * @date 2018年6月13日 上午10:30:58
	 */
	@Override
	public Resp updateProCountingTask(ProCountingTask proCountingTask) {
		proCountingTask.setStauts("1");
		Integer updateCnt = proCountingTaskMapper.update(proCountingTask);
		if (updateCnt.intValue() == 1) {
			return success();
		} else {
			return fail("更改状态失败");
		}
	}

}
